<?php
/*
  +------------------------------------------------------------------------+
  | PLU																	   |
  +------------------------------------------------------------------------+
  | Copyright (c) 2013-2015 PLU Team (http://www.plu.cn)				   |
  +------------------------------------------------------------------------+
  | This source file is subject to the New BSD License that is bundled     |
  | with this package in the file docs/LICENSE.txt.                        |
  |                                                                        |
  | If you did not receive a copy of the license and are unable to         |
  | obtain it through the world-wide-web, please send an email             |
  | to license@zephir-lang.com so we can send you a copy immediately.      |
  +------------------------------------------------------------------------+
  | Authors: wolftankk <wolftankk@plu.cn								   |
  +------------------------------------------------------------------------+
*/
ini_set('display_errors', 'on');
error_reporting(E_ALL ^ E_NOTICE);

/**
 * 在apps中的app名必须要与域名中做匹配
 * 每个app中可以自我构建不懂的module
 * 所有静态类的文件全部放在public中。
 */
call_user_func(function() {
	function throwNotFound() {
		header("HTTP/1.1 404 NOT FOUND");
	}

	$apps_dir = dirname(__DIR__).DIRECTORY_SEPARATOR."apps";
	$current_module = $_GET['__m'];
	unset($_GET['__m']);
	if (empty($current_module)) {
		return throwNotFound();
	}
	
	$app_dir = $apps_dir.DIRECTORY_SEPARATOR.$current_module;
	$app_bootstrap_file = $app_dir.DIRECTORY_SEPARATOR."bootstrap.php";

	if (is_dir($app_dir) && is_file($app_bootstrap_file)) {
		include $app_bootstrap_file;
	} else {
		return throwNotFound();
	}
});

?>
